In [1]:
library(WGCNA)
library(igraph)
library("flashClust")
library('stringr')
options(stringsAsFactors = FALSE);
enableWGCNAThreads();
Warning message:
"package 'WGCNA' was built under R version 3.6.3"Loading required package: dynamicTreeCut
Loading required package: fastcluster

Attaching package: 'fastcluster'

The following object is masked from 'package:stats':

    hclust



Attaching package: 'WGCNA'

The following object is masked from 'package:stats':

    cor

Warning message:
"package 'igraph' was built under R version 3.6.3"
Attaching package: 'igraph'

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union


Attaching package: 'flashClust'

The following object is masked from 'package:fastcluster':

    hclust

The following object is masked from 'package:stats':

    hclust

Warning message:
"package 'stringr' was built under R version 3.6.2"
Allowing parallel execution with up to 11 working processes.

Reading the graph file

In [18]:
setwd("D:\\FIU\\CyFinder\\Data")
df <- read.delim("Breast_Cancer.txt",header=FALSE, check.names=FALSE)
In [19]:
df
V1V2V3
ABCB1 ABCG2 469
ABCB1 ADAM23193
ABCB1 AKT1 215
ABCB1 AR 215
ABCB1 BCL2 954
ABCB1 BIRC5 352
ABCB1 CDKN1A215
ABCB1 CTSD 235
ABCB1 EGF 800
ABCB1 EGFR 284
ABCB1 ERBB2 623
ABCB1 ESR1 247
ABCB1 GLI1 227
ABCB1 GSTP1 823
ABCB1 IGF1 224
ABCB1 IL6 217
ABCB1 JUN 832
ABCB1 MGMT 643
ABCB1 NME1 274
ABCB1 NR3C1 216
ABCB1 PGR 402
ABCB1 PTEN 247
ABCB1 PTGS2 800
ABCB1 TGFB1 215
ABCB1 TP53 959
ABCG2 AKT1 815
ABCG2 ATM 916
ABCG2 BAD 297
ABCG2 BIRC5 287
ABCG2 CDH1 163
.........
SFRP1 SNAI2 567
SFRP1 TFF3 241
SFRP1 TWIST1 419
SFRP1 VEGFA 151
SLC39A6SNAI2 338
SLC39A6TGFB1 218
SLC39A6XBP1 407
SLIT2 SRC 191
SNAI2 TGFB1 297
SNAI2 TP53 920
SNAI2 TWIST1 894
SRC TGFB1 215
SRC THBS1 447
SRC TP53 215
SRC TWIST1 800
SRC VEGFA 996
TFF3 TGFB1 223
TFF3 XBP1 475
TGFB1 THBS1 913
TGFB1 TP53 705
TGFB1 TP73 218
TGFB1 VEGFA 966
THBS1 TP53 962
THBS1 TP73 650
THBS1 TWIST1 218
THBS1 VEGFA 933
TP53 TP73 970
TP53 TWIST1 833
TP53 VEGFA 961
TP73 TWIST1 165

Constructing the igraph graph object. Then plotting the graph and get the adjacency matrix from it

In [20]:
G <- graph.data.frame(d=df,directed=FALSE)
In [22]:
plot(G, vertex.label = V(G)$name)
In [31]:
adjMat <- as_adjacency_matrix(G, sparse=FALSE)
ABCB1ABCG2ADAM23AKT1APCARATMBADBCL2BIRC5...SNAI2SRCTFF3TGFB1THBS1TP53TP73TWIST1VEGFAXBP1
ABCB10 1 1 1 0 1 0 0 1 1 ...0 0 0 1 0 1 0 0 0 0
ABCG21 0 0 1 0 0 1 1 0 1 ...0 0 0 0 0 1 0 0 0 0
ADAM231 0 0 0 0 0 0 0 0 0 ...0 0 0 0 1 0 0 0 0 0
AKT11 1 0 0 1 1 1 1 1 1 ...1 1 1 1 1 1 0 1 1 1
APC0 0 0 1 0 1 0 0 1 1 ...0 1 1 1 1 1 1 0 0 0
AR1 0 0 1 1 0 1 0 1 1 ...1 1 0 1 0 1 0 0 1 0
ATM0 1 0 1 0 1 0 1 1 1 ...0 1 0 1 1 1 1 0 1 0
BAD0 1 0 1 0 0 1 0 1 1 ...0 1 0 1 1 1 0 0 1 1
BCL21 0 0 1 1 1 1 1 0 1 ...1 1 0 1 1 1 1 0 1 1
BIRC51 1 0 1 1 1 1 1 1 0 ...0 1 0 1 1 1 1 0 1 0
BRCA10 0 0 1 0 1 1 0 1 1 ...1 1 0 0 1 1 1 1 1 0
BRCA20 0 0 1 1 1 1 0 1 1 ...1 0 0 1 1 1 0 0 0 0
CCNA10 0 0 1 0 1 1 0 1 1 ...0 1 0 1 1 1 1 0 0 0
CCND10 0 0 1 1 1 1 1 1 1 ...1 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0 1 1 1 1 1 ...0 1 0 1 1 1 0 0 0 0
XBP10 0 0 1 0 0 0 1 1 0 ...0 0 1 0 0 0 0 0 0 0
In [33]:
head(adjMat)
ABCB1ABCG2ADAM23AKT1APCARATMBADBCL2BIRC5...SNAI2SRCTFF3TGFB1THBS1TP53TP73TWIST1VEGFAXBP1
ABCB11 1 1 1 0 1 0 0 1 1 ...0 0 0 1 0 1 0 0 0 0
ABCG21 1 0 1 0 0 1 1 0 1 ...0 0 0 0 0 1 0 0 0 0
ADAM231 0 1 0 0 0 0 0 0 0 ...0 0 0 0 1 0 0 0 0 0
AKT11 1 0 1 1 1 1 1 1 1 ...1 1 1 1 1 1 0 1 1 1
APC0 0 0 1 1 1 0 0 1 1 ...0 1 1 1 1 1 1 0 0 0
AR1 0 0 1 1 1 1 0 1 1 ...1 1 0 1 0 1 0 0 1 0

Calculating Tom Based Dissimilarity from the Adjacency Matrix

In [106]:
tomSimilarity <- TOMsimilarity(adjMat)
tomDist = 1-tomSimilarity
..connectivity..
..matrix multiplication (system BLAS)..
..normalization..
..done.
In [107]:
rownames(tomDist) <- rownames(adjMat)
colnames(tomDist) <- colnames(adjMat)
In [108]:
collectGarbage()

Do Average Linkage Hierarchical Clustering based on TOM based dissimilarity matrix, and plot the dendrogram

In [109]:
hierADJ=hclust(as.dist(tomDist), method="average")
In [110]:
par(mfrow=c(1,1))
plot(hierADJ, main="Clustering tree based of the module eigengenes")

module identification from the result of clustering algorithm, dendrogram

In [116]:
# We like large modules, so we set the minimum module size relatively high:
minModuleSize = 4;
# Module identification using dynamic tree cut:
unmergedLabels = cutreeDynamic(dendro = hierADJ, distM = tomDist,
                                    deepSplit = 2, cutHeight = 0.21,
                                    minClusterSize = minModuleSize,
                                    pamRespectsDendro = FALSE );
unmergedColors = labels2colors(unmergedLabels)
 ..done.
In [117]:
unmergedColors
  1. 'turquoise'
  2. 'turquoise'
  3. 'grey'
  4. 'brown'
  5. 'blue'
  6. 'turquoise'
  7. 'blue'
  8. 'brown'
  9. 'brown'
  10. 'red'
  11. 'blue'
  12. 'blue'
  13. 'blue'
  14. 'blue'
  15. 'yellow'
  16. 'turquoise'
  17. 'yellow'
  18. 'yellow'
  19. 'turquoise'
  20. 'blue'
  21. 'blue'
  22. 'yellow'
  23. 'brown'
  24. 'grey'
  25. 'blue'
  26. 'brown'
  27. 'brown'
  28. 'turquoise'
  29. 'turquoise'
  30. 'turquoise'
  31. 'turquoise'
  32. 'turquoise'
  33. 'grey'
  34. 'turquoise'
  35. 'grey'
  36. 'yellow'
  37. 'yellow'
  38. 'blue'
  39. 'brown'
  40. 'brown'
  41. 'brown'
  42. 'brown'
  43. 'turquoise'
  44. 'turquoise'
  45. 'grey'
  46. 'turquoise'
  47. 'turquoise'
  48. 'turquoise'
  49. 'brown'
  50. 'green'
  51. 'yellow'
  52. 'red'
  53. 'yellow'
  54. 'turquoise'
  55. 'brown'
  56. 'turquoise'
  57. 'red'
  58. 'turquoise'
  59. 'turquoise'
  60. 'blue'
  61. 'turquoise'
  62. 'blue'
  63. 'green'
  64. 'blue'
  65. 'green'
  66. 'grey'
  67. 'yellow'
  68. 'yellow'
  69. 'blue'
  70. 'brown'
  71. 'grey'
  72. 'grey'
  73. 'grey'
  74. 'green'
  75. 'turquoise'
  76. 'brown'
  77. 'grey'
  78. 'brown'
  79. 'red'
  80. 'blue'
  81. 'blue'
  82. 'blue'
  83. 'brown'
  84. 'grey'
In [118]:
plotDendroAndColors(hierADJ, unmergedColors, "Dynamic Tree Cut",
                dendroLabels = FALSE, hang = 0.03,
                addGuide = TRUE, guideHang = 0.05)

Each cluster index and number of nodes in it

In [134]:
#first bold number is the index of the node
#2nd number is their cluster index
table(unmergedLabels)
unmergedLabels
 0  1  2  3  4  5  6 
11 22 17 16 10  4  4 

color assignment of every nodes

In [140]:
for (i in 1:84){
    print(paste(colnames(adjMat)[i],unmergedColors[i]))
}
[1] "ABCB1 turquoise"
[1] "ABCG2 turquoise"
[1] "ADAM23 grey"
[1] "AKT1 brown"
[1] "APC blue"
[1] "AR turquoise"
[1] "ATM blue"
[1] "BAD brown"
[1] "BCL2 brown"
[1] "BIRC5 red"
[1] "BRCA1 blue"
[1] "BRCA2 blue"
[1] "CCNA1 blue"
[1] "CCND1 blue"
[1] "CCND2 yellow"
[1] "CCNE1 turquoise"
[1] "CDH1 yellow"
[1] "CDH13 yellow"
[1] "CDK2 turquoise"
[1] "CDKN1A blue"
[1] "CDKN1C blue"
[1] "CDKN2A yellow"
[1] "CSF1 brown"
[1] "CST6 grey"
[1] "CTNNB1 blue"
[1] "CTSD brown"
[1] "EGF brown"
[1] "EGFR turquoise"
[1] "ERBB2 turquoise"
[1] "ESR1 turquoise"
[1] "ESR2 turquoise"
[1] "FOXA1 turquoise"
[1] "GATA3 grey"
[1] "GLI1 turquoise"
[1] "GRB7 grey"
[1] "GSTP1 yellow"
[1] "HIC1 yellow"
[1] "ID1 blue"
[1] "IGF1 brown"
[1] "IGF1R brown"
[1] "IGFBP3 brown"
[1] "IL6 brown"
[1] "JUN turquoise"
[1] "KRT18 turquoise"
[1] "KRT19 grey"
[1] "KRT5 turquoise"
[1] "KRT8 turquoise"
[1] "MAPK1 turquoise"
[1] "MAPK3 brown"
[1] "MAPK8 green"
[1] "MGMT yellow"
[1] "MKI67 red"
[1] "MLH1 yellow"
[1] "MMP2 turquoise"
[1] "MMP9 brown"
[1] "MUC1 turquoise"
[1] "MYC red"
[1] "NME1 turquoise"
[1] "NOTCH1 turquoise"
[1] "NR3C1 blue"
[1] "PGR turquoise"
[1] "PLAU blue"
[1] "PRDM2 green"
[1] "PTEN blue"
[1] "PTGS2 green"
[1] "PYCARD grey"
[1] "RARB yellow"
[1] "RASSF1 yellow"
[1] "RB1 blue"
[1] "SERPINE1 brown"
[1] "SFN grey"
[1] "SFRP1 grey"
[1] "SLC39A6 grey"
[1] "SLIT2 green"
[1] "SNAI2 turquoise"
[1] "SRC brown"
[1] "TFF3 grey"
[1] "TGFB1 brown"
[1] "THBS1 red"
[1] "TP53 blue"
[1] "TP73 blue"
[1] "TWIST1 blue"
[1] "VEGFA brown"
[1] "XBP1 grey"